package com.cmc.cloud.cmclink.doc.controller.admin;

import cn.hutool.core.bean.BeanUtil;
import com.cmc.cloud.cmclink.doc.constants.UrlConstants;
import com.cmc.cloud.cmclink.doc.vo.portspecialrequestvo.PortSpecialRequestCreateReqVO;
import com.cmc.cloud.cmclink.doc.vo.portspecialrequestvo.PortSpecialRequestPageReqVO;
import com.cmc.cloud.cmclink.doc.vo.portspecialrequestvo.PortSpecialRequestRespVO;
import com.cmc.cloud.cmclink.doc.vo.portspecialrequestvo.PortSpecialRequestUpdateReqVO;
import com.cmes.framework.biz.advice.annotations.UseResponsePropertyAdvice;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import org.springframework.validation.annotation.Validated;
import com.cmes.framework.common.pojo.CommonResult;
import com.cmes.framework.common.pojo.PageResult;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;
import java.util.*;

import com.cmc.cloud.cmclink.doc.entity.PortSpecialRequestDO;
import com.cmc.cloud.cmclink.doc.service.PortSpecialRequestService;


/**
 * 接货地或目的地单证特殊要求配置前端接口Controller
 *
 * @author codegen
 */
@Tag(name = "管理后台 - 接货地或目的地单证特殊要求配置")
@RestController
@Validated
@RequestMapping(UrlConstants.APPLICATION_URL + "/portSpecialRequest")
public class PortSpecialRequestController {

    @Resource
    private PortSpecialRequestService portSpecialRequestService;

    @Operation(summary = "创建接货地或目的地单证特殊要求配置")
    @PostMapping("/create")
    @PreAuthorize("@ss.hasPermission('doc:docSpecialRequirements:add')")
    public CommonResult<Void> createPortSpecialRequest(@Valid @RequestBody PortSpecialRequestCreateReqVO createReqVO) {
        portSpecialRequestService.createPortSpecialRequest(createReqVO);
        return CommonResult.success();
    }

    @Operation(summary = "更新接货地或目的地单证特殊要求配置")
    @PostMapping("/update")
    @PreAuthorize("@ss.hasPermission('doc:docSpecialRequirements:edit')")
    public CommonResult<Void> updatePortSpecialRequest(@Valid @RequestBody PortSpecialRequestUpdateReqVO updateReqVO) {
        portSpecialRequestService.updatePortSpecialRequest(updateReqVO);
        return CommonResult.success();
    }

    @Operation(summary = "删除接货地或目的地单证特殊要求配置")
    @PostMapping("/delete/{id}")
    @Parameter(name = "id", description = "id", required = true)
    @PreAuthorize("@ss.hasPermission('doc:docSpecialRequirements:delete')")
    public CommonResult<Void> deletePortSpecialRequest(@PathVariable("id") Long id) {
        portSpecialRequestService.deletePortSpecialRequest(id);
        return CommonResult.success();
    }

    @Operation(summary = "获得接货地或目的地单证特殊要求配置")
    @GetMapping("/get/{id}")
    @Parameter(name = "id", description = "id", required = true, example = "1024")
    public CommonResult<PortSpecialRequestRespVO> getPortSpecialRequest(@PathVariable("id") Long id) {
        PortSpecialRequestDO portSpecialRequest = portSpecialRequestService.getPortSpecialRequest(id);
        return CommonResult.success(BeanUtil.copyProperties(portSpecialRequest, PortSpecialRequestRespVO.class));
    }

    @Operation(summary = "获得接货地或目的地单证特殊要求配置列表")
    @GetMapping("/list")
    @Parameter(name = "ids", description = "id列表", required = true, example = "1024,2048")
    public CommonResult<List<PortSpecialRequestRespVO>> getPortSpecialRequestList(@RequestParam("ids") Collection<Long> ids) {
        List<PortSpecialRequestDO> list = portSpecialRequestService.getPortSpecialRequestList(ids);
        return CommonResult.success(BeanUtil.copyToList(list, PortSpecialRequestRespVO.class));
    }

    @Operation(summary = "筛选接货地或目的地单证特殊要求配置列表")
    @GetMapping("/filterList")
    public CommonResult<List<PortSpecialRequestRespVO>> filterPortSpecialRequestList(@RequestParam("porCode") String porCode, @RequestParam("delCode") String delCode) {
        List<PortSpecialRequestDO> list = portSpecialRequestService.filterPortSpecialRequestList(porCode, delCode);
        return CommonResult.success(BeanUtil.copyToList(list, PortSpecialRequestRespVO.class));
    }

    @Operation(summary = "获得接货地或目的地单证特殊要求配置分页")
    @PostMapping("/getPage")
    @UseResponsePropertyAdvice
    @PreAuthorize("@ss.hasPermission('doc:docSpecialRequirements:search')")
    public CommonResult<PageResult<PortSpecialRequestRespVO>> getPortSpecialRequestPage(@RequestBody PortSpecialRequestPageReqVO pageVO) {
        PageResult<PortSpecialRequestDO> pageResult = portSpecialRequestService.getPortSpecialRequestPage(pageVO);
        List<PortSpecialRequestRespVO> results = BeanUtil.copyToList(pageResult.getList(), PortSpecialRequestRespVO.class);
        return CommonResult.success(new PageResult<>(results, pageResult.getTotal()));
    }
}
